'use strict' import commentService from '../../../../src/data/bots/{id}/comments/{commentId}' import { authenticate, checkRole } from '../../../../auth' import { Operation } from 'express-openapi' /** * Operations on /bots/{id}/comments/{commentId} */ export default function() { /**Updates comment with commendId */ const PATCH: Operation = async (req, res, next) => { const { isAllowedUser, role } = req.user if (!isAllowedUser && !checkRole(role, 'comment')) { console.error('No permission to post comments') res.status(401).send() } else { try { res.status(200).json(await commentService.patchComment(req)) } catch (error) { res.status(error.code || 500).send(error.message) } } } return { PATCH: [authenticate(['allowed-users', 'bot-token']), PATCH] } }